package com.huirui.server.pojo.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@Data
public class ShortDatedProductDto {

    @NotNull(message = "商品ID不能为空")
    @Positive(message = "商品ID必须为正整数")
    @Schema(description = "商品ID")
    private Long productId;

    @NotNull(message = "生产日期不能为空")
    @PastOrPresent(message = "生产日期不能晚于当前日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Schema(description = "生产日期")
    private LocalDate manufacturingDate;

    @NotNull(message = "过期时间不能为空")
    @Future(message = "过期时间必须晚于当前日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Schema(description = "过期时间")
    private LocalDate expiryDate;

    @NotNull(message = "商品规格列表不能为空")
    @Size(min = 1, message = "商品规格列表至少包含1条数据")
    @Valid // 级联校验内部类的注解
    @Schema(description = "商品规格列表")
    private List<ShortDatedProductSpecificationDto> specifications;

    @Data
    public static class ShortDatedProductSpecificationDto {

        @NotNull(message = "商品规格ID不能为空")
        @Positive(message = "商品规格ID必须为正整数")
        @Schema(description = "商品规格ID")
        private Long productSpecificationId;

        @NotNull(message = "促销价格不能为空")
        @DecimalMin(value = "0.01", message = "促销价格必须大于0")
        @DecimalMax(value = "99999999.99", message = "促销价格不能超过99999999.99")
        @Digits(integer = 8, fraction = 2, message = "促销价格最多支持8位整数、2位小数")
        @Schema(description = "促销价格")
        private BigDecimal promotionalPrice;

        @NotNull(message = "规格库存不能为空")
        @Min(value = 0, message = "规格库存不能为负数")
        @Max(value = 99999, message = "规格库存不能超过99999")
        @Schema(description = "规格库存")
        private Long stock;
    }
}
